﻿using System.IO;
using System.Linq;
using BioinformaticAlgoritms2014;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;

namespace BioinformaticAlgoritms2014Test
{
    
    
    /// <summary>
    ///This is a test class for SequenceTest and is intended
    ///to contain all SequenceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SequenceTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for DNASequence Constructor
        ///</summary>
        [TestMethod()]
        public void SequenceConstructorTest()
        {
            string sequence = string.Empty; 
            DNASequence target = new DNASequence(sequence);
            Assert.IsTrue(true);
        }

        ///// <summary>
        /////A test for Find
        /////</summary>
        //[TestMethod()]
        //public void FindTest()
        //{
        //    string sequence = string.Empty; // TODO: Initialize to an appropriate value
        //    DNASequence target = new DNASequence(sequence); // TODO: Initialize to an appropriate value
        //    int k = 0; // TODO: Initialize to an appropriate value
        //    int l = 0; // TODO: Initialize to an appropriate value
        //    int t = 0; // TODO: Initialize to an appropriate value
        //    string[] expected = null; // TODO: Initialize to an appropriate value
        //    string[] actual;
        //    actual = target.Find(k, l, t);
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        /// <summary>
        ///A test for GetFrequentWords
        ///</summary>
        [TestMethod()]
        public void GetFrequentWordsTest()
        {
            var lines = File.ReadAllLines(Tools.GetFullPath(@"DataSets\frequent_words_data.txt"));
            DNASequence target = new DNASequence(lines[1]);
            int k = int.Parse(lines[2]);
            string[] expected = lines[4].Split(' ');
            string[] actual;
            actual = target.GetFrequentWords(k);
            Assert.IsTrue(Tools.CompareArray(expected, actual));

        }

        /// <summary>
        ///A test for GetHammingDistance
        ///</summary>
        [TestMethod()]
        public void GetHammingDistanceTest()
        {
            var target = new DNASequence("GGGCCGTTGGT");
            const string seq = "GGACCGTTGAC"; 
            const int expected = 3; 
            int actual = target.GetHammingDistance(seq);
            Assert.AreEqual(expected, actual);
          
        }

        /// <summary>
        ///A test for GetPatternCount
        ///</summary>
        [TestMethod()]
        public void GetPatternCountTest()
        {
            var lines = File.ReadAllLines(Tools.GetFullPath(@"DataSets\ApproximatePattern.txt"));
            DNASequence target = new DNASequence(lines[1]);
            string pattern = lines[2]; 
            int mismatches = int.Parse(lines[3]);
            int expected = int.Parse(lines[5]); ; 
            int actual;
            actual = target.GetPatternCount(pattern, mismatches);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for GetPatternMatchesIndexes
        ///</summary>
        [TestMethod()]
        public void GetPatternMatchesIndexesTest()
        {
           var lines= File.ReadAllLines(Tools.GetFullPath(@"DataSets\approximate_match_data.txt"));
            DNASequence target = new DNASequence(lines[2]);
            string pattern = lines[1];
            int mismatches = int.Parse(lines[3]); 
            int[] expected = Tools.ParseStringToIntArray(lines[5]); 
            int[] actual;
            actual = target.GetPatternMatchesIndexes(pattern, mismatches);
            Assert.IsTrue(Tools.CompareArray(actual,expected));

        }

        ///// <summary>
        /////A test for GetReverseComplement
        /////</summary>
        //[TestMethod()]
        //public void GetReverseComplementTest()
        //{
        //    string sequence = string.Empty; // TODO: Initialize to an appropriate value
        //    DNASequence target = new DNASequence(sequence); // TODO: Initialize to an appropriate value
        //    string expected = string.Empty; // TODO: Initialize to an appropriate value
        //    string actual;
        //    actual = target.GetReverseComplement();
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        ///// <summary>
        /////A test for GetSkew
        /////</summary>
        //[TestMethod()]
        //public void GetSkewTest()
        //{
        //    string sequence = string.Empty; // TODO: Initialize to an appropriate value
        //    DNASequence target = new DNASequence(sequence); // TODO: Initialize to an appropriate value
        //    int[] expected = null; // TODO: Initialize to an appropriate value
        //    int[] actual;
        //    actual = target.GetSkew();
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}

        /// <summary>
        ///A test for GetFrequentWords
        ///</summary>
        [TestMethod()]
        public void GetFrequentWordsTest1()
        {
            var lines = File.ReadAllLines(Tools.GetFullPath(@"DataSets\frequent_words_mismatch_data_1.txt"));
            DNASequence target = new DNASequence(lines[1]);
            string[] param = lines[2].Split(' ');
            int k = int.Parse(param[0]); 
            int mismatches = int.Parse(param[1]); 
            string[] expected = lines[4].Split(' ');
            string[] actual;
            actual = target.GetFrequentWords(k, mismatches);
            CollectionAssert.AreEqual(actual,expected);
        

        }
    }
}
